﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ObjOrganizer;

namespace BLOrganizer
{
    public class BLCalendar
    {
        #region Variables

        private DLOrganizer.DLCalendar DL;

        #endregion

        #region Constructors

        public BLCalendar()
        {
            DL = new DLOrganizer.DLCalendar();
        }

        #endregion

        #region Calendar
        public DataTable GetFullCalendar(int UserId, int Month, int Year)
        {
            try
            {
                return DL.GET_FullCalendar(UserId, Month, Year);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public Dictionary<string, string> GetCalendar(int UserId, int Month, int Year)
        {
            try
            {
                return DL.GET_Calendar(UserId, Month, Year);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<string> GetCalendarDay(int UserId, int Day, int Month, int Year)
        {
            try
            {
                return DL.GET_CalendarDay(UserId, Day, Month, Year);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void AddCalendar(int UserId, DateTime Date, string Color, string Msg)
        {
            try
            {
                DL.ADD_Calendar(UserId, Date, Color, Msg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DeleteCalendar(int CalendarId)
        {
            try
            {
                DL.DEL_Calendar(CalendarId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }

    public class BLMovies
    {
        #region Variables

        private DLOrganizer.DLMovies DL;

        #endregion

        #region Constructors

        public BLMovies()
        {
            DL = new DLOrganizer.DLMovies();
        }

        #endregion

        #region Movies

        public DataTable GetMovies()
        {
            try
            {
                return DL.GET_Movies();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable GetMoviesByUser(int UserId)
        {
            try
            {
                return DL.GET_MoviesByUser(UserId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable GetMovieById(int MovieId)
        {
            try
            {
                return DL.GET_MovieById(MovieId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void AddMovie(int UserId, string Name, string Type, string ViewedDate, string Score)
        {
            try
            {
                DL.ADD_Movie(UserId, Name, Type, ViewedDate, Score);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdateMovie(int MovieId, string Name, string Type, string ViewedDate, string Score)
        {
            try
            {
                DL.UPD_Movie(MovieId, Name, Type, ViewedDate, Score);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DeleteMovie(int MovieId)
        {
            try
            {
                DL.DEL_Movie(MovieId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }

    public class BLTvShows
    {
        #region Variables

        private DLOrganizer.DLTvShows DL;

        #endregion

        #region Constructors

        public BLTvShows()
        {
            DL = new DLOrganizer.DLTvShows();
        }

        #endregion

        #region TvShows

        public DataTable GetTvShows()
        {
            try
            {
                return DL.GET_TvShows();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable GetTvShowsByUser(int UserId)
        {
            try
            {
                return DL.GET_TvShowsByUser(UserId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable GetTvShowById(int TvShowId)
        {
            try
            {
                return DL.GET_TvShowById(TvShowId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void AddTvShow(int UserId, string Name, int EpisodeNumber, int SeasonNumber, int LastViewedEpisode, string ReleaseDay, string Score)
        {
            try
            {
                DL.ADD_TvShow(UserId, Name, EpisodeNumber, SeasonNumber, LastViewedEpisode, ReleaseDay, Score);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdateTvShow(int TvShowId, string Name, int EpisodeNumber, int SeasonNumber, int LastViewedEpisode, string ReleaseDay, string Score)
        {
            try
            {
                DL.UPD_TvShow(TvShowId, Name, EpisodeNumber, SeasonNumber, LastViewedEpisode, ReleaseDay, Score);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DeleteTvShow(int TvShowId)
        {
            try
            {
                DL.DEL_TvShow(TvShowId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }

    public class BLBooks
    {
        #region Variables

        private DLOrganizer.DLBooks DL;

        #endregion

        #region Constructors

        public BLBooks()
        {
            DL = new DLOrganizer.DLBooks();
        }

        #endregion

        #region Books

        public DataTable GetBooks()
        {
            try
            {
                return DL.GET_Books();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable GetBooksByUser(int UserId)
        {
            try
            {
                return DL.GET_BooksByUser(UserId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataTable GetBookById(int BookId)
        {
            try
            {
                return DL.GET_BookById(BookId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void AddBook(int UserId, string Name, string Type, bool Completed)
        {
            try
            {
                DL.ADD_Book(UserId, Name, Type, Completed);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdateBook(int BookId, string Name, string Type, bool Completed)
        {
            try
            {
                DL.UPD_Book(BookId, Name, Type, Completed);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DeleteBook(int BookId)
        {
            try
            {
                DL.DEL_Book(BookId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }

    public class BLUsers
    {
        #region Variables

        private DLOrganizer.DLUsers DL;

        #endregion

        #region Constructors

        public BLUsers()
        {
            DL = new DLOrganizer.DLUsers();
        }

        #endregion

        #region Users

        public int GetUser(string UserName, string Password)
        {
            try
            {
                int UserId = DL.GET_User(UserName.ToLower(), Password.ToLower());
                return UserId;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ObjUser GetUserInfoById(int UserId)
        {
            try
            {
                return DL.GET_UserInfoById(UserId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void AddUser(string Name, string Password)
        {
            try
            {
                DL.ADD_User(Name, Password);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool ChangePassword(string OldPass, string NewPass, string UserName, int UserId)
        {
            try
            {
                ObjUser UserInfo = GetUserInfoById(UserId);
                if (!OldPass.Equals(UserInfo.Password)) { return false; }
                DL.UPD_User(UserName, NewPass, UserId);
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool ChangeUsername(string OldUser, string NewUser, string Pass, int UserId)
        {
            try
            {
                ObjUser UserInfo = GetUserInfoById(UserId);
                if (!OldUser.Equals(UserInfo.Name)) { return false; }
                DL.UPD_User(NewUser, Pass, UserId);
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }

    public class BLReports
    {
        #region Variables

        private DLOrganizer.DLReports DL;

        #endregion

        #region Constructors

        public BLReports()
        {
            DL = new DLOrganizer.DLReports();
        }

        #endregion

        #region Users

        public void AddReport(int UserId, string ReportType, string Message)
        {
            try
            {
                DL.ADD_Report(UserId, ReportType, Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
